package edu.gyc.hivhr.service.impl;

import edu.gyc.hivhr.model.Hr;
import edu.gyc.hivhr.dao.HrDao;
import edu.gyc.hivhr.service.HrService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2019-12-03
 */
@Service
public class HrServiceImpl extends ServiceImpl<HrDao, Hr> implements HrService {

    @Autowired
    private HrDao hrDao;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        Hr hr=lambdaQuery().eq(Hr::getUsername,s).one();
        if (hr == null) {
            throw new UsernameNotFoundException("用户名不正确！");
        }

        hr.setRoles(hrDao.getHrRolesById(hr.getId()));
        return hr;
    }
}
